<?php
include("configuration.inc.php");
if (isset($_SERVER['DOCUMENT_ROOT']) && $_SERVER['DOCUMENT_ROOT'] != "") {
    require($_SERVER['DOCUMENT_ROOT'] . '/sanitize.inc.php');
} else {
    require('sanitize.inc.php');
}
//PARANOID, SQL, SYSTEM, HTML, INT, FLOAT, LDAP, UTF8
//echo sanitize($Test, $Flags);
//var_dump($_GET);
/* Connect to an ODBC database using driver invocation */

try {
//      error_log("Trying to Connect");
    $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
    die("Died in Connection");
}
if (isset($_GET['view']) && $_GET['view'] != "") {
    $view = sanitize($_GET['view'], PARANOID);
} else {
    $view = 'RoundedLast7Days';
}

echo $view;
$sql = "SELECT * FROM :view WHERE dateutc >= DATE_ADD(CURDATE(), INTERVAL -7 DAY)";
try {
    $sth = $dbh->prepare($sql);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
    die("Died in Prepare");
}

try {
    $sth->execute(array(':view' => $view));
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
    die("Died in execute");
}

$tableData = $sth->fetchAll(PDO::FETCH_ASSOC);

$jsonData = json_encode($tableData, JSON_NUMERIC_CHECK);

print $jsonData;


